package com.edu.service.impl;

import com.edu.dao.RoleMapper;
import com.edu.entity.Selection;
import com.edu.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired
    private RoleMapper roleMapper;
    @Override
    public List<Selection> getSelections() {

        return roleMapper.getSelections();
    }
    @Override
    public void addRoleAssociation(Integer userId, Integer roleId) {
        roleMapper.removeRoleForUser(userId);
        int cnt = roleMapper.addRoleAssociation(userId, roleId);
        if( cnt !=1 ){
            throw new RuntimeException("设置用户角色失败。");
        }
    }
    @Override
    public void removeRoleAssociation(Integer userId) {

    }


}


